package junitTests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class ListSortedFilesTest extends SeleneseTestCase {
	@Before
	public void setUp() throws Exception {
		selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost:8888/");
		selenium.start();
	}

	@Test
	public void testDocumentSortedList() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("link=Document");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
	}
	
	@Test
	public void testImageSortedList() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("link=Image");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
	}

	@Test
	public void testAudioSortedList() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//a[contains(text(),'Audio')]");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
	}
	
	@Test
	public void testVideoSortedList() throws Exception {
		selenium.open("/login.jsp");
		selenium.type("id=username", "test@gmail.com");
		selenium.type("id=password", "test");
		selenium.click("id=login");
		selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('loginMsgPanel')", "10000");
		selenium.click("link=Continue");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
		selenium.click("//a[contains(text(),'Video')]");
		selenium.waitForPageToLoad("30000");
		assertEquals("Home | Media Vault", selenium.getTitle());
	}
	
	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
